home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / reformat.arc / REFORMAT.INC < prev    next >
Encoding:
Text File  |  1986-05-13  |  8.4 KB  |  198 lines

  1. (*
  2.  REFORMAT.INC
  3.  Inline code for Int25 and Int26 procedures, REFORMAT.PAS
  4.  Author David Kirschbaum (ABN.ISCAMS@USC-ISID) May 86.
  5.  REFORMAT.PAS author Jos Wennmacker (URC) apr '86.
  6.  
  7.  Rather than force the user to go through the assembly routine and keep
  8.  track of a bogus .COM file, I've used INLINE and two different hacks of
  9.  the original .ASM code to create Turbo Pascal inline code.
  10.  
  11.  Since we only use one Register record variable, AND it's a global one,
  12.  I stripped out passing its address as a parameter and just rely on it
  13.  being in the DS data segment.
  14.  
  15.  Because the code is so redundant (only the interrupt number is different),
  16.  I combined the two procedures, Int25 and Int26, into a new single procedure,
  17.  Int2526.  Now you must pass the interrupt number you desire (25H or 26H).
  18.  I resisted (with difficulty) the temptation for a little self-modifying code,
  19.  rather than listen to the screams on the networks!
  20.  
  21.  To use the new procedures, comment out the two external procedures:
  22.    Int25(....); External Int25.Com;
  23.    Int26(....); External Int26.Com;
  24.  
  25.  and add the new .INC file
  26.    {$I REFORMAT.INC} in their place.
  27.  
  28.  The separate Int25 and Int26 procedures are commented out but still remain
  29.  below for your edification.  To use them, go through REFORMAT.PAS and change:
  30.    Int25(Register);  to Int25;  (the read function), and
  31.    Int26(Register);  to Int26;  (the write function).
  32.  (and of course, uncomment Int25 and Int26 below, and comment out Int2526!)
  33.  
  34.  To use the new single procedure, in REFORMAT.PAS change:
  35.    Int25(Register);   to Int2526($25);  (the read function), and
  36.    Int26(Register);   to Int2526($26);  (the write function).
  37.  
  38.  This code (plus other changes I made to REFORMAT.PAS to tighten and speed
  39.  it up a little) runs perfectly on an XT clone (Gulfstream Micro Systems
  40.  80286 with a 10 Meg hard disk, 5.25" floppy, PC-DOS 3.1).
  41.  
  42.  Full credit, honors and glory for REFORMAT.PAS to the original author.
  43.  This extension is released to the Public Domain with no constraints.
  44.  
  45.  David Kirschbaum, Toad Hall
  46.  ABN.ISCAMS@USC-ISID.ARPA
  47.  3 May 86
  48.  
  49. The following is extracted from INT25.ASM which accompanied REFORMAT.PAS.
  50. I've placed here so you can see just what the inline code is trying to do.
  51. INT26.ASM had about the same header.
  52.  
  53. title   Int25 called from Turbo Pascal.
  54. subttl  Jos Wennmacker (URC) apr '86
  55.         page  60,132
  56. ;
  57. ; Performs random sector read from diskette or disk.
  58. ;
  59. ; This routine must be called from TURBO
  60. ; as follows: Int25(Regs);
  61. ; Regs is of type
  62. ;
  63. ; RegPack: record case integer of
  64. ;    1: (ax, bx, cx, dx, bp, si, di, ds, es, flags : integer):
  65. ;          2: (al, ah, bl, bh, cl, ch, dl, dh            : byte)
  66. ;          end;
  67. ;
  68. ; Before calling this routine the Regs must be set as follows:
  69. ;
  70. ; al := DriveNumber;
  71. ; cx := NumberOfSectorsToRead;
  72. ; dx := FirstSectorNumber;
  73. ; ds := seg(DTArea);
  74. ; bx := ofs(DTArea);
  75. ;
  76. ; The drivenumber must be specified as: 0 = A, 1 = B.
  77. ; Upon return to TURBO the registers in Regs are set to
  78. ; the values they had after int 25H returned.
  79. ;
  80. dsect   segment at          SP+
  81. AXreg   label   word          0
  82. ALreg   db      ?
  83. AHreg   db      ?
  84. BXreg   label   word          2
  85. BLreg   db      ?
  86. BHreg   db      ?
  87. CXreg   label   word          4
  88. CLreg   db      ?
  89. CHreg   db      ?
  90. DXreg   label   word          6
  91. DLreg   db      ?
  92. DHreg   db      ?
  93. BPreg   dw      ?             8
  94. SIreg   dw      ?             10
  95. DIreg   dw      ?             12
  96. DSreg   dw      ?             14
  97. ESreg   dw      ?             16
  98. Flags   dw      ?             18
  99. dsect   ends
  100. *)
  101.  
  102. (*
  103. PROCEDURE Int25;
  104.   {the separate read procedure}
  105.   BEGIN
  106.     Inline(
  107.    $1E            { push    ds                 ; save what we are about to clobber}
  108.   /$BE/>REGISTER  { mov     si,>Register       ; load DS:Regs (global) address}
  109.   /$8A/$04        { mov     al,byte ptr[si]    ;Regs.al}
  110.   /$8B/$5C/$02    { mov     bx,[si+2]          ;Regs.bx}
  111.   /$8B/$4C/$04    { mov     cx,[si+4]          ;Regs.cx}
  112.   /$8B/$54/$06    { mov     dx,[si+6]          ;Regs.dx}
  113.   /$56            { push    SI                 ;save Regs addr}
  114.   /$8B/$74/$0E    { mov     si,[si+14]         ;Regs.DS}
  115.   /$8E/$DE        { mov     ds,si              ;DS=Regs.DS}
  116.   /$55            { push    bp                 ; DOS destroys it}
  117.   /$FC            { cld                        ; if you don't, DOS makes a mess!}
  118.   /$CD/$25        { int     $25                ; old flags are still on the stack!}
  119.   /$5F            { pop     DI                 ;so save them here a sec}
  120.   /$5D            { pop     BP}
  121.   /$5E            { pop     SI                 ;Regs addr}
  122.   /$1F            { pop     DS                 ;Regs seg}
  123.   /$9C            { pushf                      ;move the new flags...}
  124.   /$8F/$44/$12    { pop     [si+18]            ;into as Reg.Flags}
  125.   /$89/$04        { mov     [si],ax            ;possible errors}
  126.   /$57            { push    DI                 ;old flags..}
  127.   /$9D            { popf                       ;..restored}
  128. );
  129.   {BX,CX,DX should not have changed, so no need to post Regs.}
  130.   END;  {of Int25}
  131.  
  132. PROCEDURE Int26;
  133.   {the separate write procedure}
  134.   BEGIN
  135.     Inline(
  136.    $1E            { push    ds                 ; save what we are about to clobber}
  137.   /$BE/>REGISTER  { mov     si,>Register       ; load DS:Regs (global) address}
  138.   /$8A/$04        { mov     al,byte ptr[si]}
  139.   /$8B/$5C/$02    { mov     bx,[si+2]}
  140.   /$8B/$4C/$04    { mov     cx,[si+4]}
  141.   /$8B/$54/$06    { mov     dx,[si+6]}
  142.   /$56            { push    SI                 ;Regs addr}
  143.   /$8B/$74/$0E    { mov     si,[si+14]         ;Regs.DS}
  144.   /$8E/$DE        { mov     ds,si}
  145.   /$55            { push    bp                 ; DOS destroys it}
  146.   /$FC            { cld                        ; if you don't PC-DOS makes a mess!}
  147.   /$CD/$26        { int     $26                ; flags are still on the stack!}
  148.   /$5F            { pop     DI                 ;save old flags here a sec}
  149.   /$5D            { pop     BP}
  150.   /$5E            { pop     SI                 ;DS:SI Regs addr}
  151.   /$1F            { pop     DS                 ;DS Regs (global variable) segment}
  152.   /$9C            { pushf                      ;returned flags}
  153.   /$8F/$44/$12    { pop     [si+18]            ;save as Regs.Flags}
  154.   /$89/$04        { mov     [si],ax            ;AX has any returned errors}
  155.   /$57            { push    DI                 ;old flags..}
  156.   /$9D            { popf                       ;..restored}
  157. );
  158.   {BX,CX,DX should not have changed, so no need to post Regs.}
  159.   END;  {of Int26}
  160. *)
  161.  
  162. PROCEDURE Int2526(R : BYTE);
  163.   {Uses global variable Register.  Pass $25 (read) or $26 (write)
  164.    as R for the function you desire.
  165.   }
  166.   BEGIN
  167.     Inline(
  168.    $1E            { push    ds                 ; save what we are about to clobber}
  169.   /$BE/>REGISTERs { mov     si,>Register       ; load DS:Regs (global) address}
  170.   /$8A/$04        { mov     al,byte ptr[si]    ;Regs.al}
  171.   /$8B/$5C/$02    { mov     bx,[si+2]          ;Regs.bx}
  172.   /$8B/$4C/$04    { mov     cx,[si+4]          ;Regs.cx}
  173.   /$8B/$54/$06    { mov     dx,[si+6]          ;Regs.dx}
  174.   /$56            { push    SI                 ;save Regs addr}
  175.   /$8B/$74/$0E    { mov     si,[si+14]         ;Regs.DS}
  176.   /$8E/$DE        { mov     ds,si              ;DS=Regs.DS}
  177.   /$55            { push    bp                 ; DOS destroys it}
  178.   /$FC            { cld                        ; if you don't, DOS makes a mess!}
  179.   /$80/$BE/>R/$25 { cmp     byte ptr >R[BP],$25 ;doing a read?}
  180.   /$75/$05        { jne     Do26               ; nope}
  181.   /$CD/$25        { int     $25                ; yep, do the read}
  182.   /$E9/$02/$00    { jmp     Done               ; and skip}
  183.                   {Do26:}
  184.   /$CD/$26        { int     $26                ;do the write}
  185.                   {Done:         ;old flags are still on the stack!}
  186.   /$5F            { pop     DI                 ;so save them here a sec}
  187.   /$5D            { pop     BP}
  188.   /$5E            { pop     SI                 ;Regs addr}
  189.   /$1F            { pop     DS                 ;Regs seg}
  190.   /$9C            { pushf                      ;move the new flags...}
  191.   /$8F/$44/$12    { pop     [si+18]            ;into as Reg.Flags}
  192.   /$89/$04        { mov     [si],ax            ;possible errors}
  193.   /$57            { push    DI                 ;old flags..}
  194.   /$9D            { popf                       ;..restored}
  195. );
  196.   {BX,CX,DX should not have changed, so no need to post Regs.}
  197.   END;  {of Int2526}
  198.